﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CastleOfTheDisillusioned.Input;
using GLImp;
using System.Drawing;
using CastleOfTheDisillusioned.Location.Maps;
using CastleOfTheDisillusioned.Location.Maps.Prison;
using CastleOfTheDisillusioned.Location.Maps.Mountain;
using CastleOfTheDisillusioned.Location.Maps.Forrest;

namespace CastleOfTheDisillusioned.Location {
	class Location_State : GameState {
		public static Map CurrentMap;
		public static Player CurrentPlayer = new Player();
		public static PauseMenu Menu = new PauseMenu();

		public Location_State(Map StartingMap) {
			ChangeMap(StartingMap);
		}

		public static void ChangeMap(Map NewMap) {
			CurrentMap = NewMap;
			if (CurrentMap.StartingPosition != null) {
				CurrentPlayer.X = CurrentMap.StartingPosition.X;
				CurrentPlayer.Y = CurrentMap.StartingPosition.Y;
			}
			CurrentPlayer.HSpeed = 0;
			CurrentPlayer.VSpeed = 0;
			CurrentPlayer.Facing = Direction.Right;
		}

		public static void EnterLocation(Map Map) {
			ChangeMap(Map);
			GameState.ChangeState(GameState.Location);
		}

		public static void LeaveLocation() {
			GameState.ChangeState(GameState.Overworld);
		}


		public override void Start() {
			MainCamera.CameraMain.SetZoom(32);
			GraphicsManager.SetBackground(Color.Black);
		}

		public override void Stop() {
		}

		public override void Draw() {
			CurrentMap.Draw();
			CurrentPlayer.Draw();
		}

		public static bool InMenu = false;

		public override void Update() {
			CurrentMap.Update();
			if (!InMenu) {
				CurrentPlayer.Update();
			} else {
				Menu.Update();
			}

			if (Controls.IsPressed(Control.Pause)) {
				InMenu = !InMenu;
			}

			MainCamera.CenterView(CurrentPlayer.X + 0.5, CurrentPlayer.Y - 1, CurrentMap.X, CurrentMap.Y,
				CurrentMap.X + CurrentMap.Width, CurrentMap.Y + CurrentMap.Height);
		}
	}
}
